Ext.namespace('VAS');

VAS.ArticleMenuWindow = function($config) {
	var _this = this;
	
	var $height;
	_this._getHeight = function(_height,_y) {
		if (typeof(_height) !== "undefined") {
			if (typeof(_height)==='string'&&_height.indexOf('%') > -1) {
				$height = document.body.clientHeight -_y - 190;			
			} else if(typeof(_height)==='number'){
				$height = _height - 50;
			}
		} 
		
		return $height;
	}    
	this.menu  = new Ext.tree.TreePanel({
			id               : $config.menuPanel.id,
	        useArrows        : true,
	        autoScroll       : true,
	        animate          : true,
	        enableDD         : true,
	        containerScroll  : true,
	        border           : false,
	        height			 : "100%",
			rootVisible      : false,	        
	        dataUrl          : $config.menuPanel.url,
	        height           : _this._getHeight($config.height,$config.y),
	        root: {
	        	id         : 'root',
	            nodeType   : 'async',
	       		expanded   : true,
		        text       : 'root',
	            draggable  : false
	        },
	        listeners:{
	        	"click":function(node){
	        		if (node.attributes.url != undefined) {
		        		destroyWinArray(_this);
				        var portal=   Ext.getCmp('std-panel');        
				        var postdata={panelId:node.attributes.id};
						AjaxDelegate(node.attributes.url, portal.callback, postdata,'return','');		        		
	        		}
	        	}
	        }	        
	});
	
	session.put("channelMenu",this.menu);
	
	//默认加载第一个节点所对应的窗口
	var loader = this.menu.getLoader();
	loader.on('load',function($this, $node, $response ){
		var node = _this.menu.getRootNode().firstChild;
		if (node.attributes.url != undefined) {
			destroyWinArray(_this);
	        var portal=   Ext.getCmp('std-panel');        
	        var postdata={panelId:node.attributes.id};
			AjaxDelegate(node.attributes.url, portal.callback, postdata,'return','');		        		
		}
		
	});
	
	var thisConfig = {
		closable      : false,
		autoScroll    : true,
		frame         : true,
		layout        : 'fit',
		tools         : [{
			id:'refresh',
			handler:function() {
				_this.menu.getRootNode().reload();
			}
		}],				
		items         : this.menu,
		listeners     : {
				beforedestroy : function() {
					var channelMenu = session.get("channelMenu");
					if (typeof channelMenu != undefined) {
						session.remove("channelMenu");
					}
				}
		}
	};
	var _config = $config || {};
	Ext.apply(_this, Ext.apply(thisConfig, _config));
	VAS.ArticleMenuWindow.superclass.constructor.call(_this);

};
Ext.extend(VAS.ArticleMenuWindow,VAS.BasicWindow,{
	manager:wgroup
});


Ext.reg('articlemenu-win',VAS.ArticleMenuWindow);

